package com.jz.community.moduleshopping.address.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jz.community.basecomm.utils.SHelper;
import com.jz.community.moduleshopping.R;
import com.jz.community.moduleshopping.address.bean.BaseAddressInfo;

import java.util.List;


/**
 * Created by Andy Huang on 2017/11/27.
 *
 * @description:
 */
public class UserOrderAddressListAdapter extends BaseQuickAdapter<BaseAddressInfo, BaseViewHolder> {

    private int sendType; //配送类型
    private boolean isShowAddressFrom; //跳转地址来源
    private boolean isDistributable = true;

    public UserOrderAddressListAdapter(@Nullable List<BaseAddressInfo> data, int sendType, boolean isDistributable) {
        super(R.layout.module_shopping_item_myself_shop_list, data);
        this.sendType = sendType;
        this.isDistributable = isDistributable;
    }

    public UserOrderAddressListAdapter(@Nullable List<BaseAddressInfo> data, boolean isShowAddressFrom) {
        super(R.layout.module_shopping_item_myself_shop_list, data);
        this.isShowAddressFrom = isShowAddressFrom;
    }

    @Override
    protected void convert(BaseViewHolder helper, BaseAddressInfo item) {
        ImageView is_off_limits = helper.getView(R.id.iv_is_off_limit_shop_list);
        ImageView is_not_pickup_iv = helper.getView(R.id.is_not_pickup_iv);
        TextView is_default_address = helper.getView(R.id.tv_my_shop_list_is_default);

        helper.setText(R.id.tv_my_shop_list_name, item.getName());
        helper.setText(R.id.tv_my_shop_list_phone, item.getPhone());

        if (isShowAddressFrom) {
            SHelper.gone(helper.getView(R.id.iv_edit_address), is_default_address, is_off_limits);
            helper.setText(R.id.tv_my_shop_list_address_detail, item.getAddress() + item.getAddressDetails());
        } else {
            if (item.getIsDefault() == 0) {
                is_default_address.setVisibility(View.VISIBLE);
                helper.setText(R.id.tv_my_shop_list_address_detail, item.getAddress() + item.getAddressDetails());
            } else {
                is_default_address.setVisibility(View.GONE);
                helper.setText(R.id.tv_my_shop_list_address_detail, item.getAddress() + item.getAddressDetails());
            }
        }

        /**
         * 不同配送类型处理
         */
        if (sendType == 2) {
            SHelper.vis(is_not_pickup_iv);
            SHelper.invis(is_off_limits);
        } else if (!isDistributable) {
            SHelper.invis(is_not_pickup_iv);
            SHelper.vis(is_off_limits);
        } else {
            SHelper.invis(is_not_pickup_iv);
            SHelper.invis(is_off_limits);
        }

        helper.addOnClickListener(R.id.iv_edit_address);
    }
}
